$(function(){
	
	/*加载首页产品*/
	$.getJSON(g_requestContextPath + "/p/productsIndex",function(data){
		var investCalculate = {"full":"满标计息","invest":"每日计息"};
		var units = {"day":"天","month":"月","week":"周","year":"年"};
		var products = data.list;
		var proHtml;
		for(var i =0; i < products.length; i++){
			proHtml = '<div class="list ">';
			proHtml += '<div class="tit">';
			if(products[i].proType == 'NEW_INVESTOR'){
				proHtml += '<i class="icon">新</i>';
			}else{
				proHtml += '<i class="icon1">定</i>';
			}
			proHtml += '<a href="'+g_requestContextPath+'/p/detial/'+products[i].pid+'">'+products[i].title+'</a>';
			proHtml += '<i class="u-icon"><img src="'+g_requestContextPath+'/images/listicon.png"></i></div>';
			/* n元起投    xx计息 */
			/*<i class="u-icon"><img src="'+g_requestContextPath+'/images/listicon.png"></i>*/
			//<span>'+parseInt(products[i].minInvestAmount/100)+'元起投,'+investCalculate[products[i].investCalculateTime]+'</span>
			/* 活动 */
			//<span>首单送红包 </span><span>尾单返现20元 </span><span>小米活动</span>
			proHtml += '<div class="btnBox">';
			proHtml += '<ul>';
			/*proHtml += '<li><p class="f-size "><span>'+(products[i].investRate - products[i].awardRate)+'</span>%+'+products[i].awardRate+'%</p><p>预期年化利率</p></li>';*/
			proHtml += '<li><p class="f-size "><span>'+changeRateShow(products[i].investRate,products[i].cycle,products[i].unit)+'%</p><p>预期年化利率</p></li>';
			proHtml += '<li><p class="f-size1"><span>'+products[i].cycle+'</span>'+units[products[i].unit]+'</p><p>投资期限</p></li>';
			
			proHtml += '<li class="u-li">';
			proHtml += '<div class="circle_container" id="circle_borrow_0" data-progress="0">';
			proHtml += '<svg viewBox="0 0 100 50">';
			proHtml += '<path d="M 50,50 m -48,0 a 48,48 0 1 1 96,0" stroke="#eaeaea" stroke-width="2" fill-opacity="0"></path>';
			proHtml += '<path id="path" d="M 50,50 m -48,0 a 48,48 0 1 1 96,0" stroke="rgb(236,195,70)" stroke-width="2" fill-opacity="0" style="stroke-dasharray: '+progressBar(products[i].yesAount,products[i].amount)+'px, 150.818px; stroke-dashoffset: 15.818px;"></path>';
			proHtml += '</svg>';
			proHtml += '<div class="progressbar-text" style="position: absolute; left: 50%; top: auto; padding: 0px; margin: 0px; transform: translate(-50%, 50%); color: rgb(255, 158, 0); bottom: 0px; font-family: Raleway, Helvetica, sans-serif; font-size: 2rem;"></div>';
			proHtml += '</div>';
			proHtml += '<p class="f-size2"><span>'+thousandBitSeparator(parseInt(products[i].amount/100-products[i].yesAount/100))+'</span> 元</p>';
			proHtml += '<p> 可投金额</p>';
			proHtml += '</li>';
			
			if(products[i].status == '2'){
				proHtml += '<a href="'+g_requestContextPath+'/p/detial/'+products[i].pid+'" class="u-btn">立即投资</a>';
			}else if(products[i].status == '3'){
				proHtml += '<a class="u-btn u-red">复审中</a>';
			}else if(products[i].status == '4' || products[i].status == '5'){
				proHtml += '<a class="u-btn u-yellow">计息中</a>';
			}else if(products[i].status == '6'){
				proHtml += '<a class="u-btn disabled">已还款</a>';
			}
			
			proHtml += '</ul>';
			proHtml += '</div></div>';
			
			$(".tabCon-list").append(proHtml);
		}
	});
	
});

/**
 * 投资进度条
 * @param yesAmount
 * @param amount
 * @returns
 */
function progressBar(yesAmount,amount){
	var ratio = parseFloat(yesAmount)/parseFloat(amount);
	var result = parseFloat(150.818)*parseFloat(ratio);
	return Math.round(result*100)/100 + 16;
}
/**
 * 修改利率显示方式
 * @param rate
 * @param cycle
 * @param unit
 * @returns
 */
function changeRateShow(rate,cycle,unit){
	var rateShow = rate+"</span>";
	var rateChanged = 0;
	if(unit == 'day'){
		if(cycle >= 30 && cycle < 90){
			if(rate > 8){
				rateChanged = parseFloat(new Number(rate)-8).toFixed(2);
				rateShow = "8</span>%+"+rateChanged+"";
			}
		}else if(cycle >= 90){
			if(rate > 10){
				rateChanged = parseFloat(new Number(rate)-10).toFixed(2);
				rateShow = "10</span>%+"+rateChanged+"";
			}
		}
	}else if(unit == 'month'){
		if(cycle >= 1 && cycle < 3){
			if(rate > 8){
				rateChanged = parseFloat(new Number(rate)-8).toFixed(2);
				rateShow = "8</span>%+"+rateChanged+"";
			}
		}else if(cycle >= 3){
			if(rate > 10){
				rateChanged = parseFloat(new Number(rate)-10).toFixed(2);
				rateShow = "10</span>%+"+rateChanged+"";
			}
		}
	}
	return rateShow;
}
